package com.test.mvcframework.pojo.view;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

/**
 * 模板视图解析器
 *
 * @author felix
 */
public class TemplateViewResolver implements ViewResolver {
    public static final String PREFIX = "/";

    public static final String SUFFIX = ".jsp";

    @Override
    public void render(HttpServletRequest request, HttpServletResponse response, Object result)
            throws ServletException, IOException {
        String viewName = result.toString();
        String templatePath = PREFIX + viewName + SUFFIX;
        request.getRequestDispatcher(templatePath).forward(request, response);
    }
}
